package com.gitee.wsl.mathematics.vector.ext

import com.gitee.wsl.mathematics.vector.vec2.MutableVector2
import com.gitee.wsl.mathematics.vector.vec2.Vector2
import com.gitee.wsl.mathematics.vector.vec3.MutableVector3
import com.gitee.wsl.mathematics.vector.vec3.Vector3
import com.gitee.wsl.mathematics.vector.vec4.MutableVector4
import com.gitee.wsl.mathematics.vector.vec4.Vector4

fun<T:Number> Iterable<Vector2<T, *>>.sumTo(res:MutableVector2<T,*>)  {
    var x = res.zero
    var y = res.zero
    res.run {
        for (v in this@sumTo) {
            x += v.x
            y += v.y
        }
        res.set(x, y)
    }
}

fun<T:Number> Iterable<Vector3<T, *>>.sumTo(res:MutableVector3<T,*>)  {
    var x = res.zero
    var y = res.zero
    var z = res.zero
    res.run {
        for (v in this@sumTo) {
            x += v.x
            y += v.y
            z += v.z
        }
        res.set(x, y, z )
    }
}


fun<T:Number> Iterable<Vector4<T, *>>.sumTo(res: MutableVector4<T, *>)  {
    var x = res.zero
    var y = res.zero
    var z = res.zero
    var w = res.zero
    res.run {
        for (v in this@sumTo) {
            x += v.x
            y += v.y
            z += v.z
            w += v.w
        }
        res.set(x, y, z ,w)
    }
}

